<template>
	<div class="factory_image_video_examine table-theme">
		<head-title title="审核--工厂素材审核"></head-title>
		<el-card>
			<div class="top-menu">
				<div class="menu-left">
					<tabs-view :list="classifyList" :tabsIndex="status" @roleType="stateType"></tabs-view>
					 <select-view
						:option-list="typeList"
						:value="type"
						placeholder="操作类型"
						type="type"
						@value="setSelectValue"
					>
					</select-view>
				</div>

				<div class="menu-right">
					<refresh-button @refresh="refreshPage"></refresh-button>
					<search-view :option="optionList" @value="goSearch" @clear="refreshPage"></search-view>
				</div>
			</div>
			<p class="data-number">总数据数：{{total}}</p>
			<el-table :data="examineList">
				<el-table-column label="序号" align="center" prop="image_id"></el-table-column>
				<el-table-column label="工厂序号" align="center" prop="factory_id"></el-table-column>
				<el-table-column label="图片/视频" align="center" width="80">
					<template slot-scope="scope">
						<el-popover placement="right" title="" trigger="hover">
							<img v-if="type != 1" :src="scope.row.image" style="width: 400px;" />
							<video controls="controls" v-if="type == 1" :src="scope.row.image" style="width: 400px;" />
							<img v-if="type != 1" slot="reference" :src="scope.row.image" style="width: 50px; height: 50px; vertical-align: top;" />
							<video v-if="type == 1" slot="reference" :src="scope.row.image" style="width: 50px; height: 50px; vertical-align: top;border: 1px solid #E3E3E3;" />
						</el-popover>
					</template>
				</el-table-column>		
				<el-table-column label="工厂编号	" align="center" prop="factory_sn"></el-table-column>
				<el-table-column label="工厂名称" align="center" prop="factory_name"></el-table-column>
				<el-table-column label="类型" align="center" prop="type_name"></el-table-column>
				<el-table-column label="状态" align="center" prop="examine_status_name"></el-table-column>
				<el-table-column label="拒绝原因" align="center" prop="reason"></el-table-column>
				<el-table-column label="审核时间" align="center" prop="examine_time"></el-table-column>
				<el-table-column label="申请时间" align="center" prop="add_time"></el-table-column>
				<el-table-column label="操作" align="center" width="280">
					<template slot-scope="scope">
						<el-button type="primary" size="mini" @click="operate(0, scope.row)">详情</el-button>
						<el-button v-if="scope.row.examine_status == 0" type="primary" size="mini" @click="operate(1, scope.row.image_id)">审核</el-button>
						<el-button v-if="scope.row.examine_status == 0" type="danger" size="mini" @click="operate(2, scope.row.image_id)">拒绝</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pages"><el-pagination background layout="prev, pager, next, jumper" :total="total" @current-change="init" :current-page="page"></el-pagination></div>
		</el-card>

		<!-- 拒绝原因弹框 -->
		<el-dialog title="拒绝原因" :visible.sync="remarksDialog" center :modal-append-to-body="false" width="680px">
			<el-form :model="remarksForm" :rules="remarksFormRules" ref="remarksForm" label-width="120px">
				<el-form-item label="拒绝原因:" prop="reason"><el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="remarksForm.reason"></el-input></el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="remarksDialog = false">取 消</el-button>
				<el-button type="primary" @click="confirmClick('remarksForm')">确 定</el-button>
			</span>
		</el-dialog>

		<!-- 详情弹框 -->
		<el-dialog title="详情" :visible.sync="infoDialog" center :modal-append-to-body="false" width="680px">
			<div class="info-details">
				<img v-if="type != 1" :src="info.image" />
				<video controls="controls" v-if="type == 1" :src="info.image" />
				<p v-if="type == 3">面料编号：{{ info.fabric_sn }}</p>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" v-if="info.examine_status == 0" @click="operate(1, info.image_id)">审核</el-button>
				<el-button type="danger" v-if="info.examine_status == 0" @click="operate(2, info.image_id)">拒绝</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
import SelectView from "@/components/SelectView";
import TabsView from '@/components/TabsView'
export default {
	components:{
		SelectView,
		TabsView
	},
	data() {
		return {
			info: '',
			infoDialog: false,
			optionList: [
				{
					value: 0,
					label: '工厂编号'
				},
				{
					value: 1,
					label: '工厂名称'
				}
			],
			type: 1, // 1 视频 2 照片  3 面料
			remarksDialog: false,
			remarksForm: {
				reason: ''
			},
			remarksFormRules: {
				reason: [{ required: true, message: '请输入内容' }]
			},
			serach: {
				searchContent: '',
				classSelect: '0'
			},
			examineList: [], // 审核列表
			total: 0,totalData: 0, 
			status: 0,
			page: 0,
			classifyList: ['全部', '待审核' , '通过' , '拒绝' ],
			typeList:[
				{
					label:'工厂视频',
					value:1
				},
				{
					label:'展厅照片',
					value:2
				},
				{
					label:'工厂面料',
					value:3
				}
			]
		};
	},
	methods: {
		// 初始化列表
		init(e) {
			this.page = e;
			let data = {
				page: e - 1 ? e - 1 : 0,
				limit: 10,
				type: this.type
			};
			if (this.status != 0) {
				// data.status 0 待审核 1 审核通过 2 拒绝
				data.examine_status = this.status - 1;
			}

			// classSelect 0工厂编号 1工厂名称
			if (this.serach.classSelect == 0 && this.serach.searchContent != '') {
				data.factory_sn = this.serach.searchContent;
			} else if (this.serach.classSelect == 1 && this.serach.searchContent != '') {
				data.factory_name = this.serach.searchContent;
			}

			this.$http(this.$ApiList.FactoryImageExamineList, data).then(res => {
				this.examineList = [];
				if (res.datas.length != 0) {
					this.examineList = res.datas.list;
					this.total = res.datas.count;
				}
			});
		},
		stateType(type) {
			this.status = type;
			this.init();
		},
		operate(type, id) {
			let data = {
				image_id: id
			};
			//type 0详情 1审核 2拒绝
			switch (type) {
				case 0:
					this.info = id;
					this.infoDialog = true;
					break;
				case 1:
					this.$http(this.$ApiList.FactoryImageExamineSuccess, data).then(res => {
						this.$layer.msg('操作成功');
						this.page = 1;
						this.infoDialog = false;
						this.init();
					});
					break;
				case 2:
					this.remarksDialog = true;
					this.remarksForm.image_id = id;
					break;
			}
		},
		//提交
		confirmClick(formName) {
			this.$refs[formName].validate(valid => {
				if (valid) {
					this.$http(this.$ApiList.FactoryImageExamineRefuse, this.remarksForm).then(res => {
						this.$layer.msg('操作成功');
						this.remarksDialog = false;
						this.infoDialog = false;
						this.init();
					});
				} else {
					this.$layer.msg('请填写完整信息后提交');
				}
			});
		},
		// 搜素
		goSearch(type, value) {
			this.page = 1;
			this.serach.selectContent = value;
			this.serach.classSelect = type;
			this.init();
		},
		refreshPage() {
			this.page = 1;
			this.serach.searchContent = '';
			this.status = 0;
			this.init();
		},
		setSelectValue(obj){
			const { value,type } = obj
			switch (type) {
				case 'type':
					this.type = value
					break;
			
				default:
					break;
			}
			this.init()
		}
	},
	created() {
		this.init();
	}
};
</script>
<style lang="scss">
.factory_image_video_examine {
	.info-details video,
	.info-details img {
		width: 100%;
	}
	.info-details p {
		text-align: center;
		line-height: 50px;
		font-size: 20px;
	}
}
</style>
